
package com.wonder.lab.notification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class NotificationTestActivity extends Activity {

    private NotificationManager manager;

    private int notificaton_id = 43243243;

    private Button btnShow;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        btnShow = (Button) findViewById(R.id.btnShow);
        btnShow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                showNotification(R.drawable.ic_launcher, "hello", "hello world");
            }
        });

    }

    public void showNotification(int resImage, String strTitle, String strContent) {

        Notification notification = new Notification(resImage, strTitle, System.currentTimeMillis() + 60000);
        // notification.defaults = Notification.DEFAULT_ALL; // 铃声，震动，指示灯都有
        Intent intent = new Intent(this, NotificationTestActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        notification.setLatestEventInfo(this, strTitle, strContent, pendingIntent);
        manager.notify(notificaton_id, notification);
    }
}
